package com.binarysoft.service.operlog;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.binarysoft.service.operlog.OperLog;

public class OperLogSqlProvider {

    public String insertSelective(OperLog record) {
        BEGIN();
        INSERT_INTO("OPER_LOG");
        
        VALUES("LOGID", "#{logid,jdbcType=INTEGER}");
        
        if (record.getOpername() != null) {
            VALUES("OPERNAME", "#{opername,jdbcType=VARCHAR}");
        }
        
        if (record.getOperdesc() != null) {
            VALUES("OPERDESC", "#{operdesc,jdbcType=VARCHAR}");
        }
        
        if (record.getOperstatus() != null) {
            VALUES("OPERSTATUS", "#{operstatus,jdbcType=VARCHAR}");
        }
        
        if (record.getUserId() != null) {
            VALUES("USER_ID", "#{userId,jdbcType=VARCHAR}");
        }
        
        if (record.getOperTime() != null) {
            VALUES("OPER_TIME", "#{operTime,jdbcType=DATE}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(OperLog record) {
        BEGIN();
        UPDATE("OPER_LOG");
        
        if (record.getOpername() != null) {
            SET("OPERNAME = #{opername,jdbcType=VARCHAR}");
        }
        
        if (record.getOperdesc() != null) {
            SET("OPERDESC = #{operdesc,jdbcType=VARCHAR}");
        }
        
        if (record.getOperstatus() != null) {
            SET("OPERSTATUS = #{operstatus,jdbcType=VARCHAR}");
        }
        
        if (record.getUserId() != null) {
            SET("USER_ID = #{userId,jdbcType=VARCHAR}");
        }
        
        if (record.getOperTime() != null) {
            SET("OPER_TIME = #{operTime,jdbcType=DATE}");
        }
        
        WHERE("LOGID = #{logid,jdbcType=INTEGER}");
        
        return SQL();
    }
}